#!/bin/bash
# Installation script for cdwork shell function

CDWORK_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/cdwork.sh"

echo "🔧 Installing cdwork shell function..."

# Detect shell
if [[ -n "$ZSH_VERSION" ]]; then
    SHELL_RC="$HOME/.zshrc"
    SHELL_NAME="zsh"
elif [[ -n "$BASH_VERSION" ]]; then
    SHELL_RC="$HOME/.bashrc"
    SHELL_NAME="bash"
else
    echo "❌ Unsupported shell. Please manually add to your shell configuration:"
    echo "   source '$CDWORK_SCRIPT'"
    exit 1
fi

# Check if already installed
if grep -q "source.*cdwork.sh" "$SHELL_RC" 2>/dev/null; then
    echo "✅ cdwork is already installed in $SHELL_RC"
    exit 0
fi

# Add source line to shell config
echo "" >> "$SHELL_RC"
echo "# cdwork shell function for Claude Code directory navigation" >> "$SHELL_RC"
echo "source '$CDWORK_SCRIPT'" >> "$SHELL_RC"

echo "✅ cdwork function installed in $SHELL_RC"
echo "📋 To use immediately, run: source $SHELL_RC"
echo ""
echo "🚀 Usage examples:"
echo "   cdwork           # List directories"
echo "   cdwork -l        # List directories"  
echo "   cdwork -v        # List with verbose info"
echo "   cdwork -e 1      # Enter directory #1"
echo "   cw -e 2          # Short alias to enter directory #2"